n,m=map(int,input().split())
arr=[]
flag=[]
for i in range(0,n):
    row=list(map(int,input().split()))
    arr.append(row)
    flag.append([False for j in range(0,m)])

for i in range(0,n):
    for j in range(0,m):
        if arr[i][j]==0:
            continue
        zong=1
        k=i-1
        while k>=0:
            if arr[k][j]!=arr[i][j]:
                break
            k-=1
            zong+=1
        k=i+1
        while k<n:
            if arr[k][j]!=arr[i][j]:
                break
            k+=1
            zong+=1

        if zong>=3:
            flag[i][j]=True
            k=i-1
            while k>=0:
                if arr[k][j]!=arr[i][j]:
                    break
                flag[k][j]=True
                k-=1
            k=i+1
            while k<n:
                if arr[k][j]!=arr[i][j]:
                    break
                flag[k][j]=True
                k+=1

        heng=1
        k=j-1
        while k>=0:
            if arr[i][k]!=arr[i][j]:
                break
            k-=1
            heng+=1
        k=j+1
        while k<m:
            if arr[i][k]!=arr[i][j]:
                break
            k+=1
            heng+=1

        if heng>=3:
            flag[i][j]=True
            k=j-1
            while k>=0:
                if arr[i][k]!=arr[i][j]:
                    break
                flag[i][k]=True
                k-=1
            k=j+1
            while k<m:
                if arr[i][k]!=arr[i][j]:
                    break
                flag[i][k]=True
                k+=1

for i in range(0,n):
    for j in range(0,m):
        if flag[i][j]==True:
            arr[i][j]=0

for row in arr:
    for col in row:
        print(col,end=" ")
    print("")